"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Point = exports.Mark = exports.Terrain = exports.Position = void 0;
const Utils_1 = __importDefault(require("./Utils"));
class Position {
}
exports.Position = Position;
var Terrain;
(function (Terrain) {
    Terrain[Terrain["KONG"] = 0] = "KONG";
    Terrain[Terrain["SHAN"] = 1] = "SHAN";
    Terrain[Terrain["SHUI"] = 2] = "SHUI";
    Terrain[Terrain["LIN"] = 3] = "LIN";
    Terrain[Terrain["SHA"] = 4] = "SHA";
    Terrain[Terrain["JING"] = 5] = "JING";
})(Terrain = exports.Terrain || (exports.Terrain = {}));
/** 印记 */
class Mark {
}
exports.Mark = Mark;
class Point {
    constructor(gameMgr, x, y, terrain) {
        this.position = new Position();
        this.small = null;
        this.big = null;
        this.arr_marks = new Set();
        this.is_敲山震虎_flag = false; //敲山震虎 递归用到
        this.gameMgr = gameMgr;
        this.position.x = x;
        this.position.y = y;
        this.terrain = terrain;
        this.id = Utils_1.default.getPointId(x, y);
    }
    toObj() {
        let obj = {
            "id": this.id,
            "position": this.position,
            "terrain": this.terrain,
            "arr_marks": this.markToJson()
        };
        return obj;
    }
    update() {
        this.gameMgr.sendBroadcast(Utils_1.default.getObj("update_point", { "point": this.toObj() }, true, false), false);
    }
    changeTerrain(newTerrain) {
        this.terrain = newTerrain;
        this.update();
    }
    /**
     * 客户端知道是哪个玩家的阵法就够了
     */
    markToJson() {
        let arr = [];
        for (let mark of this.arr_marks) {
            arr.push({ "type": mark.type, "username": mark.big.player.username });
        }
        return arr;
    }
    addMark(type, big) {
        let mark = new Mark();
        mark.big = big;
        mark.type = type;
        this.arr_marks.add(mark);
        this.update();
    }
    removeMark(big) {
        for (let mark of this.arr_marks) {
            if (mark.big == big) {
                this.arr_marks.delete(mark);
            }
        }
        this.update();
    }
    /**
     * 是否有这个印记
     */
    hasMark(type, player) {
        for (let mark of this.arr_marks) {
            if (type == mark.type && mark.big.player == player) {
                return true;
            }
        }
        return false;
    }
    /**
     * 获取一个不是自己的印记
     */
    getMarkNotMe(type, player) {
        for (let mark of this.arr_marks) {
            if (type == mark.type && mark.big.player != player) {
                return mark;
            }
        }
        return null;
    }
}
exports.Point = Point;
